package com.xiyu.service.repository.market.setting;

import com.xiyu.service.model.market.setting.MarketSettingReply;
import com.xiyu.service.model.market.setting.MarketSettingReplyFetcher;
import com.xiyu.service.model.market.setting.MarketSettingReplyTable;
import com.xiyu.service.model.system.user.SystemUserFetcher;
import com.xiyu.service.vo.market.marketSetting.MarketSettingReplyListInput;
import org.babyfish.jimmer.spring.repository.JRepository;

import java.util.Optional;
import java.util.List;

public interface MarketSettingReplyRepository extends JRepository<MarketSettingReply, Long> {
    MarketSettingReplyTable marketSettingReplyTable = MarketSettingReplyTable.$;

    default List<MarketSettingReply> listQuery(MarketSettingReplyListInput inputVO, List<Long> ownerUserId){
        return sql().createQuery(marketSettingReplyTable)
                .where(marketSettingReplyTable.replyAddress().likeIf(inputVO.getReplyAddress()))
                .where(marketSettingReplyTable.replyName().likeIf(inputVO.getReplyName()))
                .where(marketSettingReplyTable.ownerId().in(ownerUserId))
                .orderBy(marketSettingReplyTable.id().desc())
                .select(marketSettingReplyTable.fetch(MarketSettingReplyFetcher.$.allTableFields().owner(SystemUserFetcher.$.nickname())))
                .execute();
    }

    Optional<MarketSettingReply> findByReplyAddressAndOwnerId(String replyAddress, Long ownerId);

}